/*
 * @Author: szx
 * @Date: 2022-03-30 14:59:17
 * @LastEditTime: 2022-03-30 14:59:17
 * @Description:
 * @FilePath: \leetcode\300-399\337\337_2.js
 */
var rob = function (root) {
    // 返回值是长度为2的数组，前面表示不偷的金额，后面表示偷的金额
    const postOrder = (node) => {
        if (node == null) return [0, 0];
        const left = postOrder(node.left);
        const right = postOrder(node.right);
        const tou = node.val + left[0] + right[0];
        const butou = Math.max(left[0], left[1]) + Math.max(right[0], right[1]);
        return [butou, tou];
    };
    const res = postOrder(root);
    return Math.max(res[0], res[1]);
};
